<!--
 * @Author: 曹捷
 * @Date: 2020-07-22 10:14:26
 * @LastEditors: 曹捷
 * @LastEditTime: 2020-07-28 11:21:19
 * @Description: 区分类型 展示默认图片
--> 
<template>
  <image :mode="mode" :src="imgUrl" @click="click" />
</template>

<script>
export default {
  props: {
    type: {
      type: String,
      default: 'default',
    },
    src: {
      type: String,
      default: '',
    },
    mode: {
      type: String,
      default: 'scaleToFill',
    },
  },
  data() {
    return {
      imgUrl: '',
    }
  },
  watch: {
    src(value) {
      this.initUrl()
    },
  },
  methods: {
    click() {
      this.$emit('click')
    },
    initUrl() {
      if (this.src) {
        this.imgUrl = this.src
      } else if (this.type === 'user') {
        this.imgUrl = this.getHeadImg()
      } else if (this.type === 'man') {
        this.imgUrl = require('@/static/man.jpg')
      } else if (this.type === 'default') {
        this.imgUrl = require('@/static/default.png')
      }
    },
    getHeadImg() {
      let userInfo = uni.getStorageSync('userInfo')
      let url = require('@/static/woman.jpg')
      if (userInfo) {
        if (userInfo.photoUrl) {
          return userInfo.photoUrl
        } else if (userInfo.sex === 1) {
          return require('@/static/man.jpg')
        }
      }
      return url
    },
    getUserImg() {},
  },
  mounted() {
    this.initUrl()
  },
}
</script>

<style>
</style>